import org.newdawn.slick.gui.TextField;
import org.newdawn.slick.gui.GUIContext;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Font;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Color;

/**
* LobbyTextField is identical to Slick's TextField except for the extra constructor parameter,
* a LobbyState parent, and a method that checks for mouseClicks on the LobbyTextField. If a click
* is on the LobbyTextField, the LobbyState parent's focusField method is run.
*/
public class LobbyTextField extends TextField {

	ApplicationState parent;
	String text;
	Font f;
	Color transparent = new Color(0,0,0,0);

	public LobbyTextField(String text, GameContainer cc, Font ff, int xx, int yy, int ww, int hh, ApplicationState lb) {
		super(cc, ff, xx, yy, ww, hh);
		parent = lb;
		this.text = text;
		this.f = ff;
	}

	public void mousePressed(int button, int mx, int my) {
		if(mx >= x && mx <= x + getWidth() && my >= y && my <= y + getHeight()) {
			if (parent instanceof LobbyState) {
				((LobbyState)parent).focusField(this);
			}
			if (parent instanceof ChatLobbyState)
				((ChatLobbyState)parent).focusField(this);
		} else {
			if (parent instanceof GameSessionState) {
				((GameSessionState)parent).deactivateChat();
				setFocus(false);
			}
		}
	}

	public void render(GUIContext c, Graphics g) {

		super.setBorderColor(transparent);
		super.setBackgroundColor(transparent);

		g.setColor(new Color(0,10,30));
		g.fillRoundRect(super.getX(), super.getY()-2, super.getWidth(), super.getHeight(),6);
		g.setColor(new Color(50,100,200));
		g.setAntiAlias(true);
		g.drawRoundRect(super.getX(), super.getY()-2, super.getWidth(), super.getHeight(),6);
		g.setAntiAlias(false);

		g.setColor(Color.white);
		g.translate(2,0);
		super.render(c,g);
		g.translate(-2,0);
		g.setFont(f);
		g.setColor(new Color(190,190,190));
		g.translate(0,-4);
		g.drawString(text,x+getWidth()+10,y+f.getLineHeight()/2-4);
		g.translate(0,4);
	}
}